/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.system.service.impl;

import lombok.RequiredArgsConstructor;
import me.zhengjie.config.FileProperties;
import me.zhengjie.modules.system.domain.Supplier;
import me.zhengjie.modules.system.domain.SupplierAuditHistory;
import me.zhengjie.modules.system.repository.SupplierAuditHistoryRepository;
import me.zhengjie.modules.system.repository.SupplierRepository;
import me.zhengjie.modules.system.service.SupplierAuditHistoryService;
import me.zhengjie.modules.system.service.SupplierService;
import me.zhengjie.modules.system.service.dto.SupplierAuditHistoryDto;
import me.zhengjie.modules.system.service.dto.SupplierAuditHistoryQueryCriteria;
import me.zhengjie.modules.system.service.dto.SupplierDto;
import me.zhengjie.modules.system.service.dto.SupplierQueryCriteria;
import me.zhengjie.modules.system.service.mapstruct.SupplierAuditHistoryMapper;
import me.zhengjie.modules.system.service.mapstruct.SupplierMapper;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.enums.AuditEnum;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * @author berry
 * @website https://docs.auauz.net
 * @description 服务实现
 * @date 2020-06-06
 **/
@Service
@RequiredArgsConstructor
public class SupplierAuditHistoryServiceImpl implements SupplierAuditHistoryService {

    private final SupplierAuditHistoryRepository supplierAuditHistoryRepository;
    private final SupplierAuditHistoryMapper supplierAuditHistoryMapper;

    @Override
    public Map<String, Object> queryAll(SupplierAuditHistoryQueryCriteria criteria, Pageable pageable) {
        Page<SupplierAuditHistory> page = supplierAuditHistoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        return PageUtil.toPage(page.map(supplierAuditHistoryMapper::toDto));
    }

    @Override
    public SupplierAuditHistoryDto create(SupplierAuditHistory resources) {
        return supplierAuditHistoryMapper.toDto(supplierAuditHistoryRepository.save(resources));
    }
}